Skip to content

Update to Silverstripe 6 - #20

Open
wernerkrauss wants to merge 1 commit into
NightJar:masterfrom
wernerkrauss:update-ss6
Open

Update to Silverstripe 6#20
wernerkrauss wants to merge 1 commit into
NightJar:masterfrom
wernerkrauss:update-ss6

Conversation

@wernerkrauss

@wernerkrauss wernerkrauss commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Upgrade to SS6 and PHP8.3; fixed errors in tests and complaints by my IDE's code analysis tools.

Fixes #19

@NightJar NightJar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly comments of curiosity - but one bug found :)

Looks good, thanks for this!

I haven't had time to look into CMS 6 yet, so this is a great way to get familiar with some of the changes (e.g. removal of Controller::has_curr) - I appreciate the input, sorry it's taken a bit longer than thought to get to its review.

Comment thread src/Slug.php
if ($relationName && ($parent = $owner->$relationName()) && $parent->hasMethod('Link')) {
$link = $parent->Link($action);
} elseif (Controller::has_curr()) {
} elseif (Controller::curr() === null) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the exact opposite of what we want 😉
The next statement is $link = (null)->Link($action) in this case.

Since has_curr was deleted I guess it should be !== instead.
It could use assignment as to not call the function twice, but I'll leave it for you to decide.

Comment thread src/Slug.php
$count = 1;
while ($collisionList->filter($filter)->exists()) {
$owner->URLSlug = $owner->URLSlug . $count++;
$owner->URLSlug .= $count++;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated because this is just syntactic change, but it occurs to me we might end up with slug12345 instead of slug5 😂 - should probably write a test at some point (no need to do it for this PR though).

Comment thread src/SlugHandler.php
/**
* Fetches the slugged item at the end of a route (slime trail).
*
* @return DataObject

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the use statement was removed we should either:

  • make this line fully qualified
  • reinstate the use statement so it resolves

'Index ok' .
'<% end_if %>';
return SSViewer::fromString($testTemplate);
return parent::getViewer($action);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep test resources (i.e. templates in this case) separate from functional ones. Since there's no easy way to "set a tests template folder", inlining the template as a string seems like the best option.

This also removes the ability to override the template and make the test fail (not that anyone should override "Tests" namespace templates, but no option to is more reliable - in testing we want reliability).

Comment thread tests/Stubs/NewsPage.php
private static $has_many = [
'Articles' => Article::class,
'Journalists' => Journalist::class,
'Journalists' => Journalist::class . '.NewsPages',

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems redundant, there aren't multiple relation declarations to mix up with.
Is it a requirement in CMS 6, a personal preference, or an automation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's a RelationValidationService complaining, when you don't have it set correctly. See https://www.s2-hub.com/articles/validate-orm-relations-in-silverstripe/

IMHO being more declarative here is a good thing, as it makes the dev think more about relations and might prevent errors in the future.

Comment thread tests/SlugHandlerTest.php
$this->assertEquals(404, $output->getStatusCode());
$output = $this->get('news/contributors/jimbo-the-journo');
$this->assertEquals('Jimbo the Journo', $output->getBody());
$this->assertEquals('Jimbo the Journo', trim((string) $output->getBody()));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an issue with the output? The trim call should be unnecessary; I'd rather not mutate the output under assertion to make a test pass - it should pass without interference.

Perhaps I misunderstand and the behaviour of getBody has changed?

Same for the other 2 calls above.

Comment thread tests/SlugHandlerTest.php
'class' => Slug::class,
'constructor' => ['Name', 'NewsPages'],
$config->set(Journalist::class, 'extensions', [
Slug::class . '("Name")'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change also neglects to carry over the second parameter to the constructor.

Am I correct in recalling that the test didn't pass previously? 😬
I think I originally wrote it at the same time as silverstripe/silverstripe-framework#8444

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afair the second param didn't pass before, so it was useless.

Comment thread tests/SlugTest.yml
@@ -1,5 +1,6 @@
Nightjar\Slug\Tests\Stubs\NewsPage:
holder:
Title: News Holder

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a "remove confusion" change? Or something CMS 6 demands of its fixtures?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think without any param, the fixture wasn't generated. Might have worked before, but even back then I'd consider that unclear / not clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to SS6

2 participants